<template>
  <div class="exam-list">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>考试列表</span>
        </div>
      </template>

      <el-table :data="examList" style="width: 100%">
        <el-table-column prop="name" label="考试名称" />
        <el-table-column prop="subject" label="科目" />
        <el-table-column prop="startTime" label="开始时间" />
        <el-table-column prop="duration" label="考试时长" />
        <el-table-column prop="status" label="状态">
          <template #default="scope">
            <el-tag :type="getStatusType(scope.row.status)">
              {{ getStatusText(scope.row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180">
          <template #default="scope">
            <el-button 
              type="primary" 
              link
              @click="enterExam(scope.row.id)"
              :disabled="!canEnterExam(scope.row.status)"
            >
              进入考试
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 模拟考试数据
const examList = ref([
  {
    id: 1,
    name: '期中考试',
    subject: '数学',
    startTime: '2024-04-10 09:00',
    duration: '120分钟',
    status: 'upcoming'
  },
  {
    id: 2,
    name: '月考',
    subject: '英语',
    startTime: '2024-04-15 14:00',
    duration: '90分钟',
    status: 'inProgress'
  }
])

// 获取状态标签类型
const getStatusType = (status) => {
  const typeMap = {
    upcoming: 'info',
    inProgress: 'success',
    ended: 'warning',
    graded: ''
  }
  return typeMap[status]
}

// 获取状态文本
const getStatusText = (status) => {
  const textMap = {
    upcoming: '即将开始',
    inProgress: '进行中',
    ended: '已结束',
    graded: '已批改'
  }
  return textMap[status]
}

// 检查是否可以进入考试
const canEnterExam = (status) => {
  return status === 'inProgress'
}

// 进入考试
const enterExam = (examId) => {
  router.push(`/student/exam/${examId}`)
}
</script>

<style scoped>
.exam-list {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 